自动获取/system分区

chengzhenyu %!s(int64=7) %!d(string=hace) años
padre
commit
3a344bbe93
Se han modificado 1 ficheros con 35 adiciones y 1 borrados
  1. 35 1
      app/src/main/java/ai/pai/lensman/App.java

+ 35 - 1
app/src/main/java/ai/pai/lensman/App.java

@@ -16,10 +16,13 @@ import com.nostra13.universalimageloader.utils.StorageUtils;
16 16
 
17 17
 import java.io.BufferedInputStream;
18 18
 import java.io.BufferedOutputStream;
19
+import java.io.BufferedReader;
19 20
 import java.io.DataOutputStream;
20 21
 import java.io.File;
22
+import java.io.FileInputStream;
21 23
 import java.io.FileOutputStream;
22 24
 import java.io.IOException;
25
+import java.io.InputStreamReader;
23 26
 import java.lang.reflect.Field;
24 27
 import java.util.ArrayList;
25 28
 
@@ -147,7 +150,7 @@ public class App extends Application{
147 150
 
148 151
                     String cmd = "chmod 777 " + getPackageCodePath();
149 152
                     String cmd2 = "chmod -R 0777 /dev/bus/usb" ;
150
-                    String cmd3 = "mount -o rw,remount /dev/block/platform/mtk-msdc.0/by-name/system /system" ;
153
+                    String cmd3 = "mount -o rw,remount "+getSystemBlockAddr()+" /system" ;
151 154
                     String cmd5 = "cp -fr /mnt/sdcard/lensman/so/.  /system/lib" ;
152 155
 
153 156
                     String cmd6 = "" ;
@@ -197,6 +200,37 @@ public class App extends Application{
197 200
 
198 201
     }
199 202
 
203
+    private String getSystemBlockAddr(){
204
+        String path = null;
205
+        Process process = null;
206
+        DataOutputStream os = null;
207
+        try {
208
+            String cmd = "mount | grep /system >/mnt/sdcard/lensman/system_path.txt";
209
+            process = Runtime.getRuntime().exec("su");
210
+            os = new DataOutputStream(process.getOutputStream());
211
+            os.writeBytes(cmd + "\n");
212
+            os.writeBytes("exit\n");
213
+            os.flush();
214
+            process.waitFor();
215
+            FileInputStream f=new FileInputStream("/mnt/sdcard/lensman/system_path.txt");
216
+            BufferedReader tmp_reader=new BufferedReader(new InputStreamReader(f));
217
+            String tmp=tmp_reader.readLine();
218
+            path = tmp.substring(0,tmp.indexOf(" "));
219
+            LogHelper.d("czy","/system asolute path is -->"+path);
220
+        } catch (Exception e) {
221
+            LogHelper.d("czy","getSystemBlockAddr exception occur -->"+e);
222
+        } finally {
223
+            try {
224
+                if (os != null) {
225
+                    os.close();
226
+                }
227
+                process.destroy();
228
+            } catch (Exception e) {
229
+            }
230
+        }
231
+        return path;
232
+    }
233
+
200 234
     private static boolean deleteDir(File dir) {
201 235
         if (dir.isDirectory()) {
202 236
             String[] children = dir.list();